from django.db import models
from thesocialstockmarket.users.models import *
from django.contrib.auth.models import User
# Create your models here.
#===============================================================================
# Fluctuation: the change of stock at a specific date
#===============================================================================
class Fluct(Model):
    stock = ForeignKey(Stock, related_name = 'fluctuations')
    date = DateTimeField(auto_now_add=True) 
    price = FloatField(blank = True, null = True)
    change = FloatField(blank = True, null = True)
    volume = FloatField(blank = True, null = True)
    avg_daily_volume = FloatField(blank = True, null = True)
    stock_exchange = CharField(max_length = 100, blank = True, null = True)
    market_cap = CharField(max_length = 100, blank = True, null = True)
    book_value = FloatField(blank = True, null = True)
    ebitda = CharField(max_length = 100, blank = True, null = True)
    dividend_per_share = FloatField(blank = True, null = True)
    dividend_yield = FloatField(blank = True, null = True)
    earnings_per_share = FloatField(blank = True, null = True)
    week52_high = FloatField(blank = True, null = True)
    week52_low = FloatField(blank = True, null = True)
    day50_moving_avg = FloatField(blank = True, null = True)
    day200_moving_avg = FloatField(blank = True, null = True)
    price_earnings_ratio = FloatField(blank = True, null = True)
    price_earnings_growth_ratio = FloatField(blank = True, null = True)
    price_sales_ratio = FloatField(blank = True, null = True)
    price_book_ratio = FloatField(blank = True, null = True)
    short_ratio = FloatField(blank = True, null = True)


#===============================================================================
# FluctuationRecommendation:a text form for users to write the information  
#about the stock according to Fluctuation table. 
#===============================================================================
class FluctRec(AbstractRec):
    stock = ForeignKey(Stock, related_name = '%(class)s_related')
    fluct = ForeignKey(Fluct, related_name = '%(class)s_related')

    date = DateTimeField(auto_now_add=True)
    class Meta:
        unique_together = (("stock","user"),)
        get_latest_by = 'date'
#===============================================================================
# FeedBack: feedback for the fluctuation recommendation
#===============================================================================
class FluctRecRating(AbstractRating):
    fluct_rec = ForeignKey(FluctRec, related_name = '%(class)s_rating ')

    class Meta:
        unique_together = (("fluct_rec","user"),)
